﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cashier
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
            
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            //if (DatabaseServices.checkConnectionDb())
            {
                using (DatabaseServices service = new DatabaseServices())
                {
                    if (service.Login(txt_username.Text, txt_password.Text))
                    {
                        //this.Hide();
                        //new list_form().Show();
                        //new customer_form().Show();
                        //FormManager.pushForm(new customer_form());
                        FormManager.pushForm(new list_form());
                    }
                    else
                    {
                        MessageBox.Show("Wrong username or password", "Login failed!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            //else
            //{
            //    using (DatabaseServices service = new DatabaseServices())
            //    {
            //        if (service.Login(txt_username.Text, txt_password.Text))
            //        {
            //            FormManager.pushForm(new customer_form_offline());
            //        }
            //        else
            //        {
            //            MessageBox.Show("Wrong username or password", "Login failed!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //        }
            //    }
            //}
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                using (DatabaseServices service = new DatabaseServices())
                {
                    if (service.Login(txt_username.Text, txt_password.Text))
                    {
                        this.Hide();
                        //new list_form().Show();
                        new customer_form().Show();
                    }
                    else
                    {
                        MessageBox.Show("Wrong username or password", "Login failed!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);

        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        
    }
}
